package login;

import java.util.ArrayList;

import dbTable.ACCOUNT;

public class LoginBean {
	private String name;
	private String email;
	private String hideEm;
	private String[] pass;
	private String pw;
	private String exe;
	private int result;
	private String nickName;
	private ArrayList<String> err = new ArrayList<String>();	
	public static final int OK = 1;
	public static final int FAIL = 2;
	private LoginBean LoginBean;
	private String[] error = new String[2];
	public LoginBean(){
		this.LoginBean = this;
	}
	public void setMain(){
		pass = new String[]{};
		ACCOUNT a = new ACCOUNT();
		Object[] parameter={email};
		String[][] data = a.select
				("SELECT name,nickName,email FROM ACCOUNT WHERE email=?", parameter);		
		name = data[0][0];
		nickName = data[0][1];
		email = data[0][2];
		pass = new String[]{name,nickName,email};
	}
	
	public String[] getPass() {
		return pass;
	}
	public void setPass(String[] pass) {
		this.pass = pass;
	}
	public void hideMain(){
		ACCOUNT a = new ACCOUNT();
		Object[] parameter={hideEm};
		String[][] data = a.select
				("SELECT name,nickName,email FROM ACCOUNT WHERE email=?", parameter);		
		name = data[0][0];
		nickName = data[0][1];
		email = data[0][2];
	}
	

	public String getHideEm() {
		return hideEm;
	}
	public void setHideEm(String hideEm) {
		this.hideEm = hideEm;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public static int getFail() {
		return FAIL;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getPw() {
		return pw;
	}
	public void setPw(String pw) {
		this.pw = pw;
	}
	public String getExe() {
		
		if(email==null || "".equals(email) ){
			//error[0] = "(帳號)email沒有填";
			err.add("(帳號)email沒有填");
			result = LoginBean.FAIL;
			return "";
		}
		if(pw==null || "".equals(pw) ){
			//error[1] = "(密碼)password沒有填";
			err.add("(密碼)password沒有填");
			result = LoginBean.FAIL;
			return "";
		}
		if (err.size()==0){
			ACCOUNT a = new ACCOUNT();
			Object[] parameter ={email,pw};
			String[][] check = a.select("SELECT * FROM account WHERE email=? AND pw= ?", parameter);		
			if (check!=null){
				result = LoginBean.OK;
			}else{
				//error[2] = "帳密不對,請在確認";
				err.add("帳密不對,請在確認");
				result = LoginBean.FAIL;
				return "";
			}
		}
		return null;
	}
	public void setExe(String exe) {
		this.exe = exe;
	}
	public int getResult() {
		return result;
	}
	public void setResult(int result) {
		this.result = result;
	}
	public String getNickName() {
		return nickName;
	}
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	public ArrayList<String> getErr() {
		return err;
	}
	public void setErr(ArrayList<String> err) {
		this.err = err;
	}
	public static int getOk() {
		return OK;
	}
	public String[] getError() {
		return error;
	}
	public void setError(String[] error) {
		this.error = error;
	}
	
}
